package org.bozo.im.service.protocols.xmpp.stanza.util.jabber.client;

import java.util.Hashtable;

public enum XMPPPresence {

	DO_NOT_DISTURB("dnd"),
	AWAY("away"),
	CHAT("chat"),
	EXTENDED_AWAY("xa");
	
	private static Hashtable<String, XMPPPresence> mPresences;
	
	static {
		mPresences = new Hashtable<String, XMPPPresence>();
		addPresence(DO_NOT_DISTURB);
		addPresence(AWAY);
		addPresence(CHAT);
		addPresence(EXTENDED_AWAY);
	}
	
	private static void addPresence(XMPPPresence pPresence) {
		mPresences.put(pPresence.toString(), pPresence);
	}
	
	public static XMPPPresence valueOfPresence(String pPresence) {
		return mPresences.get(pPresence);
	}
	
	private XMPPPresence(String pStatus) {
		mStatus = pStatus;
	}
	
	private String mStatus;
	
	@Override
	public String toString() {
		return mStatus;
	}

	public org.bozo.im.common.types.Presence toCommonPresence() {
		
		org.bozo.im.common.types.Presence lRes = org.bozo.im.common.types.Presence.OFFLINE;
		
		switch(this) {
		
		case AWAY:
			lRes = org.bozo.im.common.types.Presence.AWAY;
			break;
			
		case CHAT:
			lRes = org.bozo.im.common.types.Presence.ONLINE;
			break;
			
		case DO_NOT_DISTURB:
			lRes = org.bozo.im.common.types.Presence.BUSY;
			break;
			
		case EXTENDED_AWAY:
			lRes = org.bozo.im.common.types.Presence.BUSY;
			break;
			
		}
		
		return lRes;
	}
}
